import { Controller, Get, UseFilters } from '@nestjs/common';
import { CustomExceptionFilter } from '../filter/customexception.filter';
import { ProductsService } from '../service/products.service';

@Controller('products')
@UseFilters(CustomExceptionFilter) // 在控制器级别应用过滤器
export class ProductsController {
  constructor(private readonly productsService: ProductsService) {}

  // 正常的路由方法
  @Get()
  findAll() {
    return this.productsService.findAll();
  }

  // 测试 HttpException 的路由
  @Get('error-test')
  testHttpException() {
    return this.productsService.throwHttpException();
  }

  // 测试普通错误的路由
  @Get('generic-error')
  testGenericError() {
    return this.productsService.throwGenericError();
  }
}